package mo.tags.stack;

public class L921 {

    public int minAddToMakeValid(String s) {
        int leftCount = 0;
        int rightCount = 0;
        for (char c : s.toCharArray()) {
            if (c == '(') {
                leftCount++;
            } else {
                if (leftCount > 0) {
                    leftCount--;
                } else {
                    rightCount++;
                }
            }
        }
        return leftCount + rightCount;
    }


    public static void main(String[] args) {
        L921 test = new L921();
        System.out.println(test.minAddToMakeValid("()))(("));
    }

}
